<!-- 还原运营数据-弹出层 -->
<div class="xf_ht_ttc" id="xf_ht_fkzh_ttc3" style="display:none">
  <div class="xf_ht_jr_obu_width xf_ht_jr_aqsz_width">
    <div class="xf_ht_sjhg3_table_box">
      <table border="0" cellspacing="0" cellpadding="0"
        class="xf_ht_sjhg3_table">
        <tr>
          <td width="200"><input type="radio" name="from" value=0>从备份数据还原</td>
          <td>
            <a onclick="showDBFilesWin();" class="xf_ht_baidu_button_on">选择数据库文件</a>
          </td>
        </tr>
        <tr>
          <td><input type="radio" name="from" value=1 checked="checked">从数据库操作记录中还原</td>
          <td><a onclick="showDBOperationsWin();" class="xf_ht_baidu_button_on">选择操作时间</a>
          </td>
        </tr>
      </table>
    </div>
    <div id="recover_hint" class="xf_ht_aqsz_csh_tcc1">
      重要提醒：此操作将平台的数据全部还原为备份运营状态，或者数据库操作时间<br />节点状态。
      但不包含软件相关设置。现在的运营数据将丢失，并无法找回。
    </div>
    <div class="xf_ht_aqsz_csh_input">
      <input id="btn_recover" class="xf_ht_tcc_button_ok" type="button" onclick="recover();" value="确  定">
      <input class="xf_ht_tcc_button_on" type="button" value="取  消" id="clear_recover">
    </div>
  </div>
</div>

<script type="text/javascript">

  var g_operation_id = -1;
  var g_file_id = -1;
  
  $("#clear_recover").click(function() {
      layer.closeAll();
    });
  
  function recover() {
    var from = $("input:radio[name='from']:checked").val();

    if (typeof (from) == "undefined") {
      alert("请选择还原类型");

      return;
    }

    if (from == 0) {
      if (g_file_id == -1) {
        alert("请选择备份文件");
        
        return;
      }
      
      $("#recover_hint").html("正在还原运营数据，请勿关闭此页面");
      $("#btn_recover").css("cursor", "default");
      $("#btn_recover").attr("disabled", "disabled");
    
      $.ajax({
        url : "@{recoverFromOperation()}",
        type : "POST",
        data : {
          "operationId" : g_file_id
        },
        success : function(data) {
          $("#recover_hint").html(data.msg);
          $("#btn_recover").css("cursor", "pointer");
          $("#btn_recover").removeAttr("disabled");
          alert(data.msg);

          if (data.code == 0) {
            layer.closeAll();
            location.reload();
          }
        },
        error : function() {
          $("#recover_hint").html("还原运营数据失败");
          $("#btn_recover").css("cursor", "pointer");
          $("#btn_recover").removeAttr("disabled");
          alert("还原运营数据失败");
          layer.closeAll();
        }
      });

      return;
    }

    if (from == 1) {
      if (g_operation_id == -1) {
        alert("请选择操作时间");
        
        return;
      }
      
      $("#recover_hint").html("正在还原运营数据，请勿关闭此页面");
      $("#btn_recover").css("cursor", "default");
      $("#btn_recover").attr("disabled", "disabled");
    
      $.ajax({
        url : "@{recoverFromOperation()}",
        type : "POST",
        data : {
          "operationId" : g_operation_id
        },
        success : function(data) {
          $("#recover_hint").html(data.msg);
          $("#btn_recover").css("cursor", "pointer");
          $("#btn_recover").removeAttr("disabled");
          alert(data.msg);

          if (data.code == 0) {
            location.reload();
          }
        },
        error : function() {
          $("#recover_hint").html("还原运营数据失败");
          $("#btn_recover").css("cursor", "pointer");
          $("#btn_recover").removeAttr("disabled");
          alert("还原运营数据失败");
        }
      });
    }
  }
  
  function showDBFilesWin() {
    p1 = $.layer({
      type: 1,
      area: ['650', 'auto'],
      title: '数据库备份文件',
      page: {dom : "#xf_htxtsz_sjkbfwj"}
    });
    //showDiv($("#xf_htxtsz_sjkbfwj"));
  }
  
  function fileDidSelect(id) {
    g_file_id = id;
  }

  function showDBOperationsWin() {
     p2 = $.layer({
      type: 1,
      area: ['650', 'auto'],
      title: '数据库操作记录',
      page: {dom : "#xf_htxtsz_sjkczjl"}
    });
    //showDiv($("#xf_htxtsz_sjkczjl"));
  }

  function operationDidSelect(id) {
    g_operation_id = id;
  }
</script>